-
Notifications
You must be signed in to change notification settings - Fork 2k
万宝锐旗直招-ethan-frontend #1841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
万宝锐旗直招-ethan-frontend #1841
Conversation
ae28049
to
7a3c9e9
Compare
} | ||
} | ||
onMouseLeave={()=>{ | ||
setAuto(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我理解这个地方可能设计的有些问题,autoplay 本质上是决定轮播图是不是自动播放的,如果这样设计的话,即使我设置了 false,点击之后又变成自动播放了
可以的话补充一些测试代码吧 |
} | ||
|
||
const Carousel: FC<CarouselProps> = ({ items, delay = 3000, autoPlay = true}) => { | ||
const [active, setActive] = useState<number>(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不用传。从初始值会自动推导
|
||
const Carousel: FC<CarouselProps> = ({ items, delay = 3000, autoPlay = true}) => { | ||
const [active, setActive] = useState<number>(0) | ||
const [auto,setAuto] = useState<boolean>(autoPlay) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
const [auto,setAuto] = useState<boolean>(autoPlay) | ||
|
||
useEffect(() => { | ||
if (active >= items.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这种边界情况是在防止什么 case, items 的变动吗,我理解如果是这样不应该是这样来处理
return | ||
} | ||
const timer = setTimeout(() => setActive((active + 1) % items.length), delay) | ||
if(!auto){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在这里用 auto 判断属于为了交互强行写逻辑了,auto 不纯粹且和交互严重耦合
}} | ||
> | ||
<div className="text-content" style={{ color: item.color }}> | ||
<h2 className="title">{item.title?.join('\r\n')}</h2> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
item.title 不存在还要展示 这个 h2 吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的 应该{item.title &&
{item.title?.join('\r\n')}
}{items.map((item, idx) => ( | ||
<li | ||
key={item.id} | ||
className={`${idx === active ? 'indicator active' : 'indicator'}`} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indicator ${idx === active ? 'active' : '‘}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这种模板字符串的话 indicator 后面会多一个空格
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indicator${idx === active ? ' active' : '‘}
No description provided.